package ${packageName};

import ${packageName}.${className};
import ${packageName}.${className}Comparator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class ${className}Demo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<${className}> dataList = new ArrayList<>();

        while (true) {
            System.out.println("\n请输入数据（每个数字用空格分隔）：");
            <#list fields as field>
            System.out.print("${field.name}: ");
            </#list>

            // 读取输入数据
            <#list fields as field>
            int ${field.name} = scanner.nextInt();
            </#list>

            ${className} data = new ${className}();
            <#list fields as field>
            data.set${field.capitalizedName}(${field.name});
            </#list>

            // 创建对象并添加到列表
            dataList.add(data);

            System.out.print("\n是否继续输入？(y/n): ");
            scanner.nextLine(); // 消费换行符
            if (!scanner.nextLine().trim().equalsIgnoreCase("y")) {
                break;
            }
        }

        // 打印原始数据
        System.out.println("\n原始数据：");
        printData(dataList);

        // 使用比较器排序
        Collections.sort(dataList, new ${className}Comparator());

        // 打印排序后的数据
        System.out.println("\n排序后的数据（从大到小）：");
        printData(dataList);
    }

    private static void printData(List<${className}> dataList) {
        for (${className} data : dataList) {
            int total = <#list fields as field>data.get${field.capitalizedName}()<#if field_has_next> + </#if></#list>;
            System.out.println(<#list fields as field>"${field.name}：" + data.get${field.capitalizedName}() + <#if field_has_next>", " + </#if></#list> " | 总和：" + total);
        }
    }
}
